#!/usr/bin/env php
<?php


if (isset($_ENV['IS_DOCKER']) && $_ENV['IS_DOCKER'] === 'ke') {
    $config = require __DIR__ . '/docker.php';
} else {
    $config = require __DIR__ . '/config.php';
}

if (empty($argv[1])) {
    echo '项目标识不能为空';
    exit;
}
$name = $argv[1];
$t = md5($config['sign'] . $name);
$file = __DIR__ . '/data/' . $name . '.php';
if (is_file($file)) {
    echo '重复的项目标识';
    exit;
}
$content = file_get_contents(__DIR__ . '/dist/build.php');
$content = str_replace(
    [
        '__BASE__',
        '__TOKEN__'
    ],
    [
        $config['base_path'] . $name,
        $t
    ], $content);

file_put_contents($file, $content);


echo 'http://' . $config['domain'] . ':' . $config['port'] . '/?name=' . $name . '&token=' . $t . "\r\n\r\n";

echo "success!\r\n";
